# -*- coding: utf-8 -*-
"""
TG选项卡组件 - TgTabWidget
选项卡容器组件，支持多页面切换
"""
from PySide6.QtWidgets import QTabWidget, QFrame
from PySide6.QtCore import Qt
from ...style_manager import StyleManager


class TgTabWidget(QTabWidget):
    """TG选项卡组件"""
    
    def __init__(self, parent=None):
        super().__init__(parent)
        # 初始化TG组件属性
        self._component_name = self.__class__.__name__
        self._is_initialized = False
        self._style_applied = False
        self._theme = 'default'
        self._size_hint = 'medium'
        
        # 初始化组件
        self.initialize()
    
    @property
    def component_name(self):
        """获取组件名称"""
        return self._component_name
    
    @property
    def is_initialized(self):
        """检查组件是否已初始化"""
        return self._is_initialized
    
    @property
    def style_applied(self):
        """检查样式是否已应用"""
        return self._style_applied
    
    def setup_ui(self):
        """设置用户界面"""
        # 设置选项卡位置
        self.setTabPosition(QTabWidget.TabPosition.North)
        # 设置选项卡可移动
        self.setMovable(True)
        # 设置文档模式
        self.setDocumentMode(True)
    
    def apply_style(self):
        """应用样式"""
        self.setStyleSheet(f"""
            QTabWidget::pane {{
                border: 1px solid {StyleManager.COLORS['border']};
                border-radius: {StyleManager.BORDER_RADIUS['medium']};
                background-color: {StyleManager.COLORS['background']};
                padding: {StyleManager.SPACING['sm']};
            }}
            QTabWidget::tab-bar {{
                alignment: left;
            }}
            QTabBar::tab {{
                background-color: {StyleManager.COLORS['surface']};
                color: {StyleManager.COLORS['text_secondary']};
                border: 1px solid {StyleManager.COLORS['border']};
                border-bottom: none;
                border-top-left-radius: {StyleManager.BORDER_RADIUS['small']};
                border-top-right-radius: {StyleManager.BORDER_RADIUS['small']};
                padding: {StyleManager.SPACING['xs']} {StyleManager.SPACING['sm']};
                margin-right: 2px;
                font-size: {StyleManager.FONT_SIZES['small']};
                min-width: 80px;
            }}
            QTabBar::tab:selected {{
                background-color: {StyleManager.COLORS['background']};
                color: {StyleManager.COLORS['text_primary']};
                border-bottom: 1px solid {StyleManager.COLORS['background']};
                font-weight: bold;
            }}
            QTabBar::tab:hover {{
                background-color: {StyleManager.COLORS['hover']};
                color: {StyleManager.COLORS['text_primary']};
            }}
            QTabBar::tab:!selected {{
                margin-top: 2px;
            }}
        """)
        self._style_applied = True
    
    def initialize(self):
        """初始化组件"""
        if not self._is_initialized:
            self.setup_ui()
            self.apply_style()
            self._is_initialized = True
            self._style_applied = True
    